package com.credithc.fastdfs.monitor.service.impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.csource.common.MyException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.credithc.fastdfs.api.entity.FdfsInfo;
import com.credithc.fastdfs.api.mapper.FdfsInfoMapper;
import com.credithc.fastdfs.monitor.jsonbean.Line;
import com.credithc.fastdfs.monitor.service.FdfsInfoService;
import com.credithc.fastdfs.monitor.util.NumUtil;
import com.credithc.framework.core.mybatis.page.PageController;
/** 
 * @ClassName: FdfsInfoServiceImpl 
 * @Description: 
 * @author zhaoc
 * @date 2015年5月19日
 * @time  上午9:38:33 
 */ 
@Service("fdfsInfoServiceImpl")
public class FdfsInfoServiceImpl implements FdfsInfoService {
	private static final Logger logger = LoggerFactory
			.getLogger(FdfsInfoServiceImpl.class);
	@Autowired
	private FdfsInfoMapper fdfsInfoMapper;
	
	@Override
	public PageController listFdfsInfo(PageController page, FdfsInfo info) {
		if(StringUtils.isNotBlank(info.getBeginDate()) || StringUtils.isNotBlank(info.getEndDate())) { //处理查询当日的日期,只限于对yyyy-MM-dd的改造
			if(!StringUtils.equals(info.getBeginDate(), info.getEndDate())) {
				if(StringUtils.isBlank(info.getBeginDate())) {
					info.setBeginDate(info.getEndDate());
				}
				if(StringUtils.isBlank(info.getEndDate())) {
					info.setEndDate(info.getBeginDate());
				}
			}
			info.setBeginDate(info.getBeginDate() + " 00:00:00");
			info.setEndDate(info.getEndDate() + " 23:59:59");
		}
		List<FdfsInfo> list = fdfsInfoMapper.selectListFileInfo(page, info);
		for(FdfsInfo f : list) {
			f.setStringFileSize(NumUtil.bytes2KB(f.getFileSize()));
		}
		page.setContent(list);
		return page;
	}

	@Override
	public List<FdfsInfo> getSystemFileCountCol(String start, String end) throws MyException {
		Date starttime, endtime;
		FdfsInfo info = new FdfsInfo();
		info.setBeginDate(start);
		info.setEndDate(end);
		return fdfsInfoMapper.getSystemFileCountCol(info);
	}

	@Override
	public List<FdfsInfo> getSystemFileCountType() throws MyException {
		return fdfsInfoMapper.getSystemFileCountCol(new FdfsInfo());
	}

}
